#include "vulkan/VKInstance.h"

void VKInstance::CreateInstance(VKValidLayersAndExts* valLayersAndExt, bool enableValidationLayers)
{
	VkApplicationInfo appInfo = {};
	appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
	appInfo.apiVersion = VK_API_VERSION_1_1;
	appInfo.pApplicationName = "VulkanRenderer";
	appInfo.applicationVersion = 1;
	appInfo.pEngineName = "VulkanEngine";
	appInfo.engineVersion = 1;
	appInfo.pNext = nullptr;

	VkInstanceCreateInfo instanceInfo = {};
	instanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
	instanceInfo.pApplicationInfo = &appInfo;
	auto extensions = valLayersAndExt->GetSDLRequiredExtensions(enableValidationLayers);
	instanceInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
	instanceInfo.ppEnabledExtensionNames = extensions.data();
	if (enableValidationLayers)
	{
		instanceInfo.enabledLayerCount = static_cast<uint32_t>(valLayersAndExt->m_RequiredValidationLayers.size());
		instanceInfo.ppEnabledLayerNames = valLayersAndExt->m_RequiredValidationLayers.data();
	}
	else {
		instanceInfo.enabledLayerCount = 0;
		instanceInfo.ppEnabledLayerNames = nullptr;
	}

	if (vkCreateInstance(&instanceInfo, nullptr, &m_Instance) != VK_SUCCESS)
		SDL_Log("failed to create vulkan instance!");
}

void VKInstance::DestroyInstance()
{
	vkDestroyInstance(m_Instance, nullptr);
}
